package com.geekaca.web;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet(urlPatterns = "/hello")
public class FirstServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        System.out.println("Hello java web servlet! ");
        String name = req.getParameter("name");
        PrintWriter writer = resp.getWriter();
        writer.write("hello " + name);
        writer.flush();
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//        String username = req.getParameter("username");
        String[] aihaos = req.getParameterValues("hobby");
//        System.out.println(username+" 欢迎访问java web, 哇哈哈2");

        if (aihaos != null) {

            for (int i = 0; i < aihaos.length; i++) {
                if (aihaos[i].equals("1")) {
                    System.out.println("旅游");
                } else if (aihaos[i].equals("2")) {
                    System.out.println("电影");
                } else if (aihaos[i].equals("3")) {
                    System.out.println("游戏");
                }
            }
        }
    }
}

